package com.yanqu.road.entity.activity.daomu;

import com.yanqu.road.entity.activity.daomu.enums.DaoMuAttHarmTypeEnum;
import com.yanqu.road.entity.activity.daomu.enums.DaoMuAttributeEnum;
import com.yanqu.road.entity.activity.daomu.enums.DaoMuNpcStatusEnum;
import com.yanqu.road.utils.property.Property;
import org.apache.regexp.RE;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DaoMuNpc {

    //唯一ID
    private long id;

    //npc配置ID
    private int npcId;

    //状态：1：存活，2：自然死亡，3：自动清理
    private int status;

    //生成时间，第几秒
    private int createTimeSecond;

    //掉落局内道具
    private Map<Integer, DaoMuBattlePropItem> dropProp;

    //减少的血量
    private long reHp = 0;

    //属性信息
    private Map<Integer, DaoMuAttribute> attributeMap;

    //伤害类型MAP，检测使用。K：类型（1:技能，2：道具：炸弹，3：自爆），V: ID_伤害。
    private List<String> harmList = new ArrayList<>();

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getNpcId() {
        return npcId;
    }

    public void setNpcId(int npcId) {
        this.npcId = npcId;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Map<Integer, DaoMuBattlePropItem> getDropProp() {
        return dropProp;
    }

    public void setDropProp(Map<Integer, DaoMuBattlePropItem> dropProp) {
        this.dropProp = dropProp;
    }

    public long getReHp() {
        return reHp;
    }

    public void setReHp(int reHp) {
        this.reHp = reHp;
    }

    public int getCreateTimeSecond() {
        return createTimeSecond;
    }

    public void setCreateTimeSecond(int createTimeSecond) {
        this.createTimeSecond = createTimeSecond;
    }

    public Map<Integer, DaoMuAttribute> getAttributeMap() {
        return attributeMap;
    }

    public void setAttributeMap(Map<Integer, DaoMuAttribute> attributeMap) {
        this.attributeMap = attributeMap;
    }

    public List<String> getHarmList() {
        return harmList;
    }

    public void addHarm(int attHarmType, int id, long reHp) {
        String value = attHarmType + "_" + id + "_" + reHp;
        this.harmList.add(value);
    }

    /**
     * 获取总血量
     * @return
     */
    public long getHp() {
        DaoMuAttribute daoMuAttribute = this.attributeMap.get(DaoMuAttributeEnum.ATTRIBUTE_HP.getType());
        return daoMuAttribute.getValue().longValue();
    }

    /**
     * 减少血量
     * @param reHp
     */
    public void reHp(long reHp) {
        this.reHp += reHp;
        if (this.reHp >= this.getHp()) {
            //npc死亡
            this.doDie();
        }
    }

    /**
     * 死亡
     */
    public void doDie() {
        this.setStatus(DaoMuNpcStatusEnum.NPC_STATUS_DIE.getStatus());
        //标记掉落的道具可使用
        if (this.getDropProp() != null && this.getDropProp().size() > 0) {
            for (DaoMuBattlePropItem npcProp : this.getDropProp().values()) {
                npcProp.setUsableFlag(true);
            }
        }
    }

    /**
     * 是否死亡
     * @return
     */
    public boolean isDie() {
        if (this.getStatus() != DaoMuNpcStatusEnum.NPC_STATUS_EXIST.getStatus()) {
            return true;
        }
        return false;
    }
}
